package com.ymttest.database.sqlwapper;

import java.util.Date;
import java.util.List;

import com.ymt.core.tool.Logger;
import com.ymt.database.SqlManager;
import com.ymttest.database.model.YmtIdPic;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;

/************************************************************************************
 * @File name : YmtUserWapper.java
 * @Author : zhouyi
 * @Date : 2015年4月2日
 * @Copyright : 洋码头
 ************************************************************************************/
public class YmtIdPicWapper {
	SqlManager manage;

	public YmtIdPicWapper() {
		manage = new SqlManager("ymt" + EnvSetup.getEnv());
	}

	/**
	 * 根据userid 查询ymtidpic
	 * 
	 * @param userid
	 * @return list
	 * @throws InterruptedException
	 */
	public List<YmtIdPic> selectIdPicByiUserId(String userid) throws InterruptedException {
		List<YmtIdPic> idPicList = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtIdPicMapper.selectByiUserId", userid);
		return idPicList;
	}

	/**
	 * insert 一条IdPic记录
	 * 
	 * @param record
	 *            YmtIdPic
	 * @return
	 * @throws InterruptedException
	 */
	public int insertIdPic(YmtIdPic record) {
		int i = manage.insert("com.ymttest.database.mapping.YmtIdPicMapper.insert", record);
		manage.commit();
		// manage.close();
		return i;
	}

	/**
	 * 根据userid 删除idpic 信息数据
	 * 
	 * @param record
	 *            YmtIdPic
	 * @return
	 * @throws InterruptedException
	 */
	public int deleterIdPicByUserId(String userid) {
		int i = manage.insert("com.ymttest.database.mapping.YmtIdPicMapper.deleterByiUserId", userid);
		manage.commit();
		// manage.close();
		return i;
	}

	/**
	 * 关闭数据库连接
	 */
	public void close() {
		manage.close();
	}

	@Override
	protected void finalize() throws Throwable {
		this.close();
		manage = null;
		super.finalize();
	}

	public static void main(String args[]) {
		YmtIdPic id = new YmtIdPic();
		id.setSid(TestDataManager.getRandomUUID().toString());
		id.setIuserid(20000342);
		id.setSname("test");
		id.setIaction(1);
		id.setScardid("0000000000000");
		id.setSidpicrightside("ss");
		id.setSidpicreverseside("aa");
		// id.setSphone("1231");
		id.setDaddtime(new Date());
		// Logger.debug(new
		// YmtIdPicWapper().selectIdPicByiUserId("2000034").size());
		// Logger.debug(new YmtIdPicWapper().insertIdPic(id));
		Logger.debug(new YmtIdPicWapper().deleterIdPicByUserId("20000342"));
	}
}
